<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Strict//EN' 'http://www.w3.org/TR/html4/strict.dtd'>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
<title>在此插入标题</title>
<link rel="stylesheet" href="../layui/layui/css/layui.css" media="all">
<script src="../layui/layui/layui.js"></script>
<script src="../js/jquery-1.8.2.js"></script>

</head>
<body>
	<form class="layui-form" action="公司信息.html">
		<div class="layui-form-item">
			<label class="layui-form-label">员工名称</label>
			<div class="layui-input-block">
				<input type="text" name="name" placeholder="请输入公司名称"
					autocomplete="off" class="layui-input" id="name">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">年龄</label>
			<div class="layui-input-block">
				<input type="text" name="age" placeholder="请输入电话"
					autocomplete="off" class="layui-input" id="age">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">介绍</label>
			<div class="layui-input-block">
				<input type="text" name="jianjie" placeholder="请输入介绍
				"autocomplete="off" class="layui-input" id="jianjie">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">人生格言</label>
			<div class="layui-input-block">
				<input type="text" name="maxim" placeholder="请输入电子邮件"
					autocomplete="off" class="layui-input" id="maxim">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">产品图片</label>
			<div class="layui-input-block">
				<button type="button" class="layui-btn" id="test1">
					<i class="layui-icon">&#xe67c;</i>上传图片
				</button>

				<span id="imgname"></span>
			</div>
		</div>

		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit lay-filter="sub">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>

		</div>
	</form>

	<script type="text/javascript">
		function getQueryString(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
			var url = decodeURI(decodeURI(window.location.search))
			var r = url.substr(1).match(reg);
			if (r != null)
				return unescape(r[2]);
			return null;
		}
		$(document).ready(function() {
			var id = getQueryString("id");
			var name = getQueryString("name");
			var img = getQueryString("img");
			var age = getQueryString("age");
			var maxim = getQueryString("maxim");
			var jianjie = getQueryString("jianjie");
			

			//方法一 :query赋值

			$("#name").val(name);
			
			$("#jianjie").val(jianjie);
			$("#maxim").val(maxim);
			$("#age").val(age);//todo....
			$("#img").attr("src", "../img/" + img);

		});
	</script>
	

	<script>
		//JavaScript代码区域
		layui.use([ 'form', 'upload', 'layer' ], function() {

			//各种基于事件的操作，下面会有进一步介绍

			var upload = layui.upload;
			var $ = layui.$;//jquery对象
			//执行实例
			var uploadInst = upload.render({
				elem : '#test1' //绑定元素
				,
				method : 'post',
				url : '../cuimg' //上传接口
				,
				done : function(res) {
					//上传完毕回调
					console.log(res);

					if (res.code == 0) {
						/* $("#test1").val(res.data); */
						$("#imgname").html(res.data);
					}
				},
				error : function() {
					//请求异常回调
					console.log(res);
				}
			});

			var form = layui.form;
			var layer = layui.layer;

			//submit 提交事件
			form.on('submit(sub)', function(data) {

				console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
				data.field.img = $("#imgname").html();
				var id = getQueryString("id");
				data.field.id = id;

				$.ajax({

					url : "../Emupda",
					type : "get",
					data : data.field,
					success : function(res) {
						layer.msg(res.msg);
					}
				});

				return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
			});
		});
	</script>

</body>
</html>